<?php

namespace App\Http\Middleware;

use App\Events\V1\UserCountChannelEvent;
use App\Helpers\RestUtils;
use App\Models\Factory\UserFactory;
use Closure;
use App\Helpers\RestResponseFactory;


/**
 * token验证中间件
 *
 * Class TokenMiddleware
 * @package App\Http\Middleware
 */
class ChannelLoginMiddleware
{
    public function handle($request, Closure $next)
    {

        $result = $next($request);
        $userphone = $request -> get('userphone');
        //验证是否成功完成
        $isComplete = $request -> get('isComplete');

        if($isComplete) {

            $channel['nid'] = $request->get('channel');
            $channel['terminal'] = $request->get('terminal');
            $channel['userphone'] = $userphone;

            //统计登录人次
            $channel['type'] = 3;
            //统计用户渠道
            event(new UserCountChannelEvent($channel));
        }
        return $result;

    }

}
